/*
 * DiscoveryPresenter.java
 * business
 *
 * Created by SunDing on 2016/9/9.
 *
 * Copyright (c) 2016年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.main.discovery.page.active;

import com.yidiandao.business.data.model.DiscoveryModel;
import com.yidiandao.business.data.model.IDiscoveryModel;
import com.yidiandao.business.ui.widget.view.SuperLoadingLayout;

import java.util.List;

/**
 * 发现-Presenter
 * <p>
 * <p>Created by ChenTao(chentao7v@gmail.com) on 2017/2/8 15:40
 */
public class DiscoveryActivePagePresenter implements DiscoveryActivePageContract.Presenter {

    private final DiscoveryActivePageContract.View mDiscoveryView;

    private IDiscoveryModel mDiscoveryModel;

    public DiscoveryActivePagePresenter(DiscoveryActivePageContract.View view) {
        mDiscoveryView = view;
        mDiscoveryModel = new DiscoveryModel();
        mDiscoveryView.setPresenter(this);
    }

    @Override
    public void start() {
        loadData(true);
    }


    @Override
    public void loadData(final boolean isRefresh) {
        mDiscoveryModel.loadDiscoveryPageData(mDiscoveryView.getPagerTag(), mDiscoveryView.getCatId(), isRefresh, new IDiscoveryModel.OnLoadDiscoveryListener<List<Object>>() {
            @Override
            public void onSuccess(List articleListBeen, boolean emptyResult, boolean hasMore) {
                if (isRefresh) {
                    mDiscoveryView.refreshContent(mDiscoveryView.checkResultObject(articleListBeen));
                    mDiscoveryView.setRefreshComplete();
                }
                mDiscoveryView.loadMoreFinish(emptyResult, hasMore);
                mDiscoveryView.setPageData(articleListBeen);

            }

            @Override
            public void onFailed() {
                if (isRefresh) {
                    mDiscoveryView.refreshContent(SuperLoadingLayout.STATE_ERROR);
                } else {
                    mDiscoveryView.loadMoreError();
                }

            }

            @Override
            public void onFinal() {

            }
        });

    }
}
